package com;

import com.fz.entity.Student;
import com.fz.mapper.StudentMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by ZCY on 2018-01-20.
 */
@Slf4j
public class Demo {
protected SqlSession session = null;
    @Before
    public void init() {
        InputStream is = null;
        try {
            is = Resources.getResourceAsStream("conf.xml");
        } catch (IOException e) {
            e.printStackTrace();
        }
        SqlSessionFactory sf = new SqlSessionFactoryBuilder().build(is);
        this.session = sf.openSession();
    }

    @After
    public void close() {
        session.commit();
        session.close();
    }

    @Test
    public  void aa(){
       StudentMapper sdao = this.session.getMapper(StudentMapper.class);
       Map<String,Object> map = new HashMap<String,Object>();
       map.put("name","张飞");
       map.put("age",199);
      //  map.clear();
       List<Student> list = sdao.query(map);
       for(Student s:list){
           log.error(s.getName());


       }

    }
    @Test
    public void bb(){
        StudentMapper sdao = this.session.getMapper(StudentMapper.class);
        Map<String,Object> map = new HashMap<String,Object>();
       map.put("name","张三");
        map.put("age",908);
        map.put("id",3);
        sdao.update(map);
    }

@Test
    public void cc(){
    StudentMapper sdao = this.session.getMapper(StudentMapper.class);
   List<Student> list = sdao.show(new int[] {3,4,5,6,7});
     for(Student s:list){
         log.error(s.toString());
     }
    }


}
